package sktit.practice.jpaint.canvas;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;

import sktit.practice.jpaint.shape.Shape;

public class PolygonCanvas extends AbstractCanvas {

	public PolygonCanvas(GC aGC, Shape aShape) {
		super(aGC, aShape);
	}
	
	public void draw()
	{
		gc.setLineStyle(SWT.LINE_SOLID);
		Point[] vertex = shape.getBorder();
		for(int i = 0; i < vertex.length - 1; i++)
			gc.drawLine(vertex[i].x, vertex[i].y, vertex[i+1].x, vertex[i+1].y);
		gc.drawLine(vertex[0].x, vertex[0].y, vertex[vertex.length - 1].x, vertex[vertex.length - 1].y);
	}
	
	public void fill(Color color)
	{
		gc.setBackground(color);
		Point[] border = shape.getBorder();
		int[] vertex =  new int[border.length*2];
		
		int i = 0;
		
		for(Point p : border)
		{
			vertex[i] = p.x;
			vertex[i+1] = p.y;
		}
		gc.fillPolygon(vertex);
	}
}
